package com.haiberg.osgi.bundle.helloword.activator;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import com.haiberg.osgi.bundle.helloservice.HelloService;
import com.haiberg.osgi.bundle.helloword.tracker.HelloServiceTracker;

public class Activator implements BundleActivator {

    //private ServiceReference<HelloService> reference;

    HelloServiceTracker helloServiceTracker;

    @Override
    public void start(BundleContext context) throws Exception {
        System.out.println("bundle.helloword start");
//		reference = (ServiceReference<HelloService>) context.getServiceReference(HelloService.class.getName());
//		HelloService service = context.getService(reference);
        helloServiceTracker = new HelloServiceTracker(context);
        helloServiceTracker.open();
        HelloService service = (HelloService) helloServiceTracker.getService();
        String content = service.sayHello();
        System.out.println(content);
    }

    @Override
    public void stop(BundleContext context) throws Exception {
//		reference = null;
        helloServiceTracker.close();
        System.out.println("bundle.helloword stop");
    }

}
